package news_create_config

import (
	"errors"
	createConfigDto "news_for_deepseek_interface/dto/admin/news/create_config"
	"news_for_deepseek_interface/model"
	"news_for_deepseek_interface/model/news"
	"time"
)

func Update(params createConfigDto.UpdateRequest) error {

	db := model.GetInstance().GetDB()

	var newsCreateConfig news.NewsCreateConfig
	if err := db.Model(&news.NewsCreateConfig{}).Where("id = ?", params.Id).First(&newsCreateConfig).Error; err != nil {
		return errors.New("配置不存在")
	}

	return model.GetInstance().GetDB().
		Model(&model.QuestionAnswerModel{}).
		Where("id = ?", params.Id).
		Updates(map[string]interface{}{
			"title":                           params.Title,
			"basis_create_type":               params.BasisCreateType,
			"basis_keywords":                  params.BasisKeywords,
			"basis_title":                     params.BasisTitle,
			"basis_description":               params.BasisDescription,
			"basis_contain_keywords":          params.BasisContainKeywords,
			"create_type":                     params.CreateType,
			"create_type_product_name":        params.CreateTypeProductName,
			"create_type_product_description": params.CreateTypeProductDescription,
			"create_type_product_rank":        params.CreateTypeProductRank,
			"create_type_competitor":          params.CreateTypeCompetitor,
			"create_type_ratio_top":           params.CreateTypeRatioTop,
			"create_type_ratio_what":          params.CreateTypeRatioWhat,
			"create_type_ratio_how":           params.CreateTypeRatioHow,
			"replace_content":                 params.ReplaceContent,
			"content_format":                  params.ContentFormat,
			"article_structure":               params.ArticleStructure,
			"article_structure_size":          params.ArticleStructureSize,
			"article_structure_title":         params.ArticleStructureTitle,
			"updated_at":                      time.Now(),
		}).Error
}
